package com.spider.lambda;

import com.spider.innerclass3.Student;

import javax.swing.*;
import java.util.Arrays;

public class Test2 {
    public static void main(String[] args) {
        test1();
        test2();
    }
    public static void test1(){
        //目标：完成给数组排序，理解其中匿名内部类的用法
        //准备一个学生类型的数组，存放6个学生对象。
        Student[] students = new Student[6];
        students[0] = new Student("殷素素",35,175.1,'女');
        students[1] = new Student("张三",18,180.1,'男');
        students[2] = new Student("王五",19,170.1,'男');
        students[3] = new Student("赵六",20,165.1,'女');
        students[4] = new Student("小七",17,160.1,'女');
        students[5] = new Student("小八",16,155.1,'女');

        Arrays.sort( students, ( o1,  o2) -> o1.getAge() - o2.getAge());
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
            System.out.println(s);
        }
    }
    public static void test2(){
        //目标：认识匿名内部类的使用场景。
        //需求：创建一个登录窗口，窗口上有一个登录按钮。
        JFrame win= new JFrame("登录界面");
        win.setSize(300,200);
        win.setLocationRelativeTo(null);    //居中显示
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        win.add(panel);


        JButton btn = new JButton("登录");
        panel.add(btn);

        //java要求必须给这个按钮添加一个点击事件监听器对象，这样就可以监听点击事件了
        btn.addActionListener( e -> System.out.println("点击了登录按钮"));
        win.setVisible(true);
    }
}

